#include "StdAfx.h"
#include "Suit.h"

#include "Case.h"
#include "../macro.h"

Suit::Suit(const char* name)
: m_name(name)
{
}

Suit::~Suit(void)
{
}

bool Suit::addCase(Case* caser)
{
	if (caser==NULL)
	{
		return false;
	}

	m_cases.push_back(caser);
	return true;
}

bool Suit::delCase(int index)
{
	if (index >= m_cases.size())
	{
		return false;
	}

	int id_of_list = 0;
	for (std::vector<Case*>::iterator iter=m_cases.begin();iter!=m_cases.end();++iter,++id_of_list)
	{
		if (index == id_of_list)
		{
			m_cases.erase(iter);
			break;
		}
	}
	return true;
}

bool Suit::run(void* param)
{
	DBG_PRINTF("%s\r\n",__FUNCTION__);

	MSG_PRINTF("[Test_Suit]%s \r\n", m_name.c_str());
	for (float index = getStart(); index < getEnd(); index += getStep())
	{
		for (std::vector<Case*>::iterator iter = m_cases.begin(); iter != m_cases.end(); ++iter)
		{
			if ((*iter) != NULL)
			{
				if (!(*iter)->run(param))
				{
					return false;
				}
			}
		}
	}

	return true;
}
std::vector<Case*> Suit::getCases()
{
	return m_cases;
}

std::string Suit::getName()
{
	return m_name;
}

std::list<loopable *> Suit::getLoopable()
{
	std::list<loopable *>  loop;
	loop.push_back(this);

	return loop;
}